package com.jatosoft.poc.priceinquiry.core.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import com.google.appengine.api.datastore.Key;

@Entity
public final class Article extends BaseDomain  {

	public Article() {
		super();
		priceRecords.add(new PriceRecord());
	}


	private static final long serialVersionUID = -2360010967289594367L;

	@Transient
	public double getLowestPrice(){
		return 0;
	}
	
	@Transient
	public double getHighestPrice(){
		return 0;
	}
	
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	public Key getId() {
		return id;
	}

	public void setId(Key id) {
		this.id = id;
	}

	public String getArticleName() {
		return articleName;
	}

	public void setArticleName(String articleName) {
		this.articleName = articleName;
	}

	public String getArticleUPC() {
		return articleUPC;
	}

	public void setArticleUPC(String articleUPC) {
		this.articleUPC = articleUPC;
	}

	public String getSpecification() {
		return specification;
	}

	public void setSpecification(String specification) {
		this.specification = specification;
	}

	public String getPackageNet() {
		return packageNet;
	}

	public void setPackageNet(String packageNet) {
		this.packageNet = packageNet;
	}

	public String getBrand() {
		return brand;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}


	String articleName;
	String articleUPC;
	String specification;
	String packageNet;
	String brand;
	List<PriceRecord> priceRecords = new ArrayList<PriceRecord>();

	@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval=true)
	public List<PriceRecord> getPriceRecords() {
		return priceRecords;
	}

	public void setPriceRecords(List<PriceRecord> priceRecords) {
		this.priceRecords = priceRecords;
	}

	@Override
	public String toString() {
		return "Article [articleName=" + articleName + ", articleUPC="
				+ articleUPC + ", specification=" + specification
				+ ", packageNet=" + packageNet + ", brand=" + brand
				+ ", priceRecords=" + priceRecords + "]";
	}

	public void addPriceRecord(PriceRecord pr){
		priceRecords.add(pr);
	}

	
}
